package com.headingdata.d7_interface_demo;

import java.util.ArrayList;

public class StudentOperatorImp2 implements StudentOperator{
    @Override
    public void printAllStudentInfo(ArrayList<Student> students) {
        System.out.println("------------全班全部学生信息如下------------");
        int boyNum = 0;
        int girlNum = 0;
        for (int i = 0; i < students.size(); i++) {
            Student s = students.get(i);
            System.out.println("姓名：" + s.getName() + ",性别：" + s.getSex() + ",成绩：" + s.getScore());
            if(s.getSex() == "男"){
                boyNum++;
            }else{
                girlNum++;
            }
            System.out.println("男生人数：" + boyNum);
            System.out.println("女生人数：" + girlNum);
            System.out.println("总人数：" + students.size());
        }
        System.out.println("==========================================");
    }

    @Override
    public void printAllStudentAverage(ArrayList<Student> students) {

        double totalScore = 0;
        double max = students.get(0).getScore();
        double min = students.get(0).getScore();
        for (int i = 0; i < students.size(); i++) {
            double s = students.get(i).getScore();
//            max = s > max ? s : max;
//            min = s < min ? s : min;
            if(s > max) max = s;
            if(s < min) min = s;
            totalScore += s;
        }
        System.out.println("全本同学的平均成绩：" + (totalScore - max -min)/(students.size() - 2));
    }
}
